package com.example.mydianping.config;

import com.example.mydianping.utils.LoginInterceptor;
import com.example.mydianping.utils.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

//使用注解的方式代替配置文件，指定拦截器
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    //该配置类被 Spring 容器管理，可以从这里拿到容器中的 stringRedisTemplate 传递给过滤器
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加更新 token 拦截器，默认先添加先拦截，也可以通过.order() 来设置拦截的先后顺序
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate));
        //添加判断是否登录的拦截器
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns("/user/code", "/user/login","/shop/**","/shop-type/list","/blog/**");
    }

}
